package com.yi.mall.consumer.controller;

import com.yi.mall.common.utils.ResponseEnum;
import com.yi.mall.common.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/mq")
public class TestController {
    @Autowired
    StreamBridge streamBridge;

    @GetMapping("/send")
    public Result send(@RequestParam String msg) {
        streamBridge.send("testOut-out-0", msg);
        return Result.success(ResponseEnum.SUCCESS, "牛逼");
    }

    @GetMapping("/payload")
    public Result payLoad(@RequestParam String msg) {
        Message<?> message = MessageBuilder.withPayload(msg)
                .setHeader("TAG", "success") // 定义消息头传递 Tag
                .build();
        streamBridge.send("testOutput-out-0", message);
        return Result.success(ResponseEnum.SUCCESS, "发送成功");
    }
}

